{template 'common/header'}
{template 'nav'}
<form id="redpackFrom">
<input type="hidden" name="id" value="{$reply['id']}" />
<div class="panel panel-default">
    <div class="panel-heading">
        活动设置
    </div>
    <div class="panel-body">
        <div class="form-group">
            <label class="col-xs-12 col-sm-3 col-md-2 control-label"><span style='color:red'>*</span> 活动名称</label>
            <div class="col-sm-9 col-xs-12">
               	<input type="text" id="activityName" required class="form-control" placeholder="" name="activityName" value="{$reply['activityName']}">
            </div>
        </div>
        <div class="form-group">
            <label class="col-xs-12 col-sm-3 col-md-2 control-label"><span style='color:red'>*</span> 提供者</label>
            <div class="col-sm-9 col-xs-12">
                <input type="text" id="provider" required class="form-control" placeholder="" name="provider" value="{$reply['provider']}">
            </div>
        </div>
        <div class="form-group">
            <label class="col-xs-12 col-sm-3 col-md-2 control-label"><span style='color:red'>*</span> 祝福语</label>
            <div class="col-sm-9 col-xs-12">
                <input type="text" id="wishing" class="form-control" placeholder="" name="wishing" value="{$reply['wishing']}">
            </div>
        </div>
        <div class="form-group">
            <label class="col-xs-12 col-sm-3 col-md-2 control-label"><span style='color:red'>*</span> 备注说明</label>
            <div class="col-sm-9 col-xs-12">
               	<textarea style="height:60px;" id='remark' name="remark" class="form-control" cols="60">{$reply['remark']}</textarea>
            </div>
        </div>
        


        
    </div>
</div>

 
<div class="panel panel-default">
    <div class="panel-heading">
        红包设置
    </div>
    <div class="panel-body">

       <div class="form-group">
            <label class="col-xs-12 col-sm-3 col-md-2 control-label"><span style='color:red'>*</span> 红包详情</label>
            <div class="col-sm-10">
                <div class="set">
                    <div class="col-sm-11" style="padding-left: 0;padding-right: 0;">
                        <div class="input-group">
                            <span class="input-group-addon">总金额</span>
                            <input type="number" class="form-control total" placeholder="元" name="total[]" value="">
                            <span class="input-group-addon">数量</span>
                            <input type="number" class="form-control num" placeholder="个" name="num[]" value="1">
                            <span class="input-group-addon">最小</span>
                            <input type="number" class="form-control min" placeholder="元" name="min[]" value="1">
                            <span class="input-group-addon">最大</span>
                            <input type="number" class="form-control max" placeholder="元" name="max[]" value="200">

                        </div>
                    </div>
                    <div class="col-sm-1">
                        <span class="fa fa-remove" style="line-height: 2.3em"></span>
                    </div>
                </div>


                <input type="button" id="add" value="增加" class="btn btn-default col-lg-10">
            </div>
        </div>

        
    </div>
</div>
    

<div class="form-group col-sm-12">
    <input type="button" id="submit" value="提交" class="btn btn-primary col-lg-1">

</div>

</form>
<script>
    $('#submit').click(function() {
        if ($("#activityName").val()=='') {
            alert("请输入活动名称!");
            return false;
        }

        if ($("#provider").val()=='') {
            alert("请输入活动主办方名称!");
            return false;
        }

        var total= $('.total');
        var num= $('.num');
        var min= $('.min');
        var max= $('.max');
        for(var i=0;i<total.size();i++){
            var t_total = parseInt(total.eq(i).val())
            var t_num   = parseInt(num.eq(i).val())
            var t_min   = parseInt(min.eq(i).val())
            var t_max   = parseInt(max.eq(i).val())


            var avg=t_total/t_num;
            if(avg < t_min){
                alert("第"+(i+1)+"次分配资金，会小于最小值")
                return;
            }
            if(avg > t_max){
                alert("第"+(i+1)+"次分配资金，会大于最大值")
                return;
            }
        }


       var data= $('#redpackFrom').serialize();
        $.post("{php echo $this->createWebUrl('save')}",data,function(res){});

    });
    $("#add").on('click',function(){
        var $this=$(this)
        var $pre=$this.prev('.set').clone();
        var inputs=$pre.find('input');
        inputs.eq(0).val('');inputs.eq(1).val('');inputs.eq(2).val(1);inputs.eq(3).val(200);
        $pre.find('.fa-remove').on('click',removeSet);
        $this.before($pre);
    })
    $('.fa-remove').on('click',removeSet);

    function removeSet(){
        if($('.set').size()==1){return false;}
        $(this).parent().parent().remove();
    }

</script>


<script language='javascript'>
    function addRule(){
         $(".btn-add-rule").button("loading");
             $.ajax({
                 url: "{php echo $this->createWebUrl('tpl',array('t'=>'rule_item'))}",
                 cache:false
             }).done(function(html){
               $(".btn-add-rule").button("reset");
               $("#rule-items").append(html);
             });
    }
    function removeRule(obj){

        $(obj).parent().parent().remove();
    }
    
    </script>

{template 'common/footer'}